<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>担保费率配置</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<script type="text/javascript">
    var grid = null;
    var pageInApp = {}; // to 下一级子窗口 接口
    var pageInTab = null;
    $(function () {
        initTab();
        var _url = '<%=path%>/fgi/fgiguarrate/initList.do?';
        $("#ligergrid1").ligerGrid({
            url: _url,
            //parms:{},
            method: 'get',
            columns: [
                {
                    display: '方案编号', name: 'programNo', minWidth: 150, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value) {
                        var d = '<a class="sq-button-hasicon" href="javascript:toDetailPage(';
                        d += "'" + rowdata.programNo + "'";
                        d += ')">' + value + '</a>';
                        return d;
                    }
                },
                {display: '费率类型', name: 'guaranteeType', align: 'left', width: 100,
                    render : function (rowdata, rowindex, value) {
                        if (value == 1) {
                            return "非风险担保费率";
                        } else {
                            return "风险担保费率";
                        }
                    }
                },
                {display: '创建者', name: 'crtUsrNm', width: 80,},
                {display: '创建时间', name: 'crtTm', width: 150,
                    render : function (rowdata, rowindex, value) {
                        return renderDate(rowdata, rowindex, value);
                    }
                },
                {display: '机构名称', name: 'orgNm', width: 150 ,},
                {display: '业务', name: 'busType', align: 'left', width: 80},
                {
                    display: '逾期天数', name: '', align: 'left', width: 60, isEllipsis: false,
                    render: function (rowdata, rowindex, value) {
                        if (StringUtils.isEmpty(rowdata.overdueBeginDay) && StringUtils.isEmpty(rowdata.overdueEndDay)) {
                            return '0';
                        } else {
                            return rowdata.overdueBeginDay + '~~' + rowdata.overdueEndDay;
                        }
                    }
                },
                {
                    display: '机构放款日期', width: 200, name: '',
                    render: function (rowdata, rowindex, value) {
                        if (StringUtils.isEmpty(rowdata.orgPayBegin) && StringUtils.isEmpty(rowdata.orgPayEnd)) {
                            return '————';
                        } else {
                            return renderDate2(rowdata.orgPayBegin) + '~~' + renderDate2(rowdata.orgPayEnd);
                        }
                    }
                },
                {
                    display: '上报时间', width: 200, name: '',
                    render: function (rowdata, rowindex, value) {
                        if (StringUtils.isEmpty(rowdata.repBegin) && StringUtils.isEmpty(rowdata.repEnd)) {
                            return '————';
                        } else {
                            return renderDate2(rowdata.repBegin) + '~~' + renderDate2(rowdata.repEnd);
                        }
                    }
                },
                {
                    display: '费率', name: 'repRate', minWidth: 60, isEllipsis: false,
                    render: function (rowdata, rowindex, value) {
                        return value + '%';
                    }
                },
                {display: '使用状态', name: 'confStatus', width: 80,
                    render : function (rowdata, rowindex, value) {
                        if (value == 1) {
                            return '使用中';
                        } else {
                            return '已作废';
                        }
                    }
                },
                {
                    display: '有效期', name: '', width: 200,
                    render: function (rowdata, rowindex, value) {
                        if (StringUtils.isEmpty(rowdata.enableBegin) && StringUtils.isEmpty(rowdata.enableEnd)) {
                            return '————';
                        } else {
                            return renderDate2(rowdata.enableBegin) + '~~' + renderDate2(rowdata.enableEnd);
                        }
                    }
                },
                getOptColumns(),
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            fixedCellHeight: false,
            rownumbers: true,
//			onAfterShowData: getFlowIds,
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();
        $('#reasonFromSet').ligerForm({
            validate: true
        });

        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            console.log(JSON.stringify(data));
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单

            });
        });
    });

    function getOptColumns() {
        var col = {
            display: '操作', width: 200, align: 'left', isEllipsis: false,
            render: function (rowdata, rowindex, value) {
                //detail
                var d = '<a class="sq-button-hasicon" href="javascript:toDetailPage(';
                d += "'" + rowdata.programNo + "'";
                d += ')"><i class="sqBtnIco_1"></i>详情</a>';
                //修改
                var g = '<a class="sq-button-hasicon" href="javascript:beInvalid(';
                g += "'" + rowdata.id + "'";
                g += ')"><i class="sqBtnIco_4"></i>作废</a>';

                return d + g;
            }
        };
        return col;
    }

    var callback = function () {
        grid.reload();
    };

    //新增数据
    function add(_guaranteeType) {
        $.ligerDialog.SQopen({
            width: 700,
            height: 'auto',
            title: '配置费率',
            url: '<%=path%>/fgi/fgiguarrate/toAddPage.do?guaranteeType=' + _guaranteeType,
            onClose: function () {
                callback();
            }
        });
    }

    function toDetailPage(_programNo) {
        if (!_programNo) return;
        $.ligerDialog.open({
            title: '详情',
            height: 'auto',
            width: 700,
            url: '<%=path%>/fgi/fgiguarrate/toDetailPage.do?programNo=' + _programNo
        });
    }

    //修改数据
    function beInvalid(_id) {
        if (!_id) return;
        $.ligerDialog.confirm('确定作废吗?', function (flag) {
            if (flag == false) return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {id: _id},
                url: '<%=path%>/fgi/fgiguarrate/beInvalid.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    function iframeResize() {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        }
        ;
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //格式化时间2
    function renderDate2(value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    var loadedTabs = [];

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function (tabid) {
                var selectedRows = grid.getSelectedRows();
                if (tabid != "tabA") {
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    }
                }
            },
            onAfterSelectTabItem: function (tabid) {

                var selectedRows = grid.getSelectedRows();
                if (tabid != "tabA") {
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    } else {
                        if (loadedTabs.indexOf(selectedRows[0].id) < 0) {
                            loadedTabs = [];
                            loadedTabs.push(selectedRows[0].id);
                            console.log(tabid);
                            switch (tabid) {
                                case "tabB":
                                    console.log(tabid)
                                    pageInTab.setTabItemSrc(tabid, "" + selectedRows[0].id);
                                    break;
                            }
                        }


                        SetIframe_height();
                    }
                }

            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

    };
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="担保费率配置" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="fieldBox">
                            <div class="label">机构名称</div>
                            <div class="field">
                                <input name="orgNm" id="orgNm" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">业务</div>
                            <div class="field">
                                <select name="busType" id="busType" data-value=" ">
                                    <option value=" " seleted>请选择</option>
                                    <c:forEach items="${splAttrCdList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="fieldBox">
                            <div class="label">逾期天数</div>
                            <div class="field">
                                <input ligerui="width: 120" name="overdueBeginDay"
                                       id="overdueBeginDay" type="text" class="ui-textbox" value=""
                                       validate="{required:true}"> - <input
                                    ligerui="width: 120" name="overdueEndDay" id="overdueEndDay"
                                    type="text" class="ui-textbox" value=""
                                    validate="{required:true}">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">机构放款日期</div>
                            <div class="field">
                                <input ligerui="width: 120" name="orgPayBegin"
                                       id="orgPayBegin" type="text" class="ui-datepicker" value=""
                                       validate="{required:true}"> - <input
                                    ligerui="width: 120" name="orgPayEnd" id="orgPayEnd"
                                    type="text" class="ui-datepicker" value=""
                                    validate="{required:true}">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">上报时间</div>
                            <div class="field">
                                <input ligerui="width: 120" name="repBegin"
                                       id="repBegin" type="text" class="ui-datepicker" value=""
                                       validate="{required:true}"> - <input
                                    ligerui="width: 120" name="repEnd" id="repEnd"
                                    type="text" class="ui-datepicker" value=""
                                    validate="{required:true}">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">使用状态</div>
                            <div class="field">
                                <select name="confStatus" id="confStatus" data-value=" ">
                                    <option value=" " seleted>请选择</option>
                                    <option value="1">使用中</option>
                                    <option value="2">已作废</option>
                                </select>
                            </div>
                        </div>

                        <div class="clearFix"></div>
                        <div class="btnsBox formBtns notRight">
                            <span id="searchBtn" class="sq-button-round">查询</span>
                            <span id="clearBtn" class="sq-button-round">清空</span>
                            <span id="addBtn1" class="sq-button-round" onclick="add(1);">非风险担保配置费率</span>
                            <span id="addBtn2" class="sq-button-round" onclick="add(2);">风险担保配置费率</span>
                            <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="sqPanel_body">
                <div id="ligergrid1" class="sq-grid"></div>
            </div>
        </div>
        <%--<div tabid="tabB" title="" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>--%>
    </div>
</div>
</body>
</html>